package com.mt.shop.controller;

import com.mt.shop.domain.User;
import com.mt.shop.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private IUserService service;

    //添加
    @RequestMapping("/add")
    public String add(String username,String password){
        service.add(username,password);
        return "add success";
    }
    //删除
    @RequestMapping("/del")
    public String del(Long userid){
        service.del(userid);
        return "del success";
    }
    //修改
    @RequestMapping("/upd")
    public String upd(){
        User user = new User();
        user.setUserid(1l);
        user.setUsername("weixy");
        service.upd(user);
        return "upd success";
    }
    //用id查询
    @RequestMapping("/getOne")
    public User getUserById(Long userid){
        User user = service.getUserById(userid);
        return user;
    }
    //查询全部
    @RequestMapping("/getAll")
    public List<User> getAll(){
        List<User> users = service.getAll();
        return users;
    }
}
